$(document).ready(function(){
	

	//发送传真对话框
	$("#sendFaxWindow").dialog({
		autoOpen : false,
		minWidth : 650,
		modal : true,
		title : '发送传真对话框',
		close : function() {
			return false;
		}
	});

    // 取消发送
   $("#selCancel").click(function() {
		$("#sendFaxWindow").dialog('close');
	});
	//棵树之间切换
	//var myType='MedicineTree';
	$("a").click(function(){return false;});
	$("#treeTypeSelect").change(function(){	
		var treeType=$(this).attr("value");	
		//alert(treeType);
		//var url = "do/medicineTree_getMedicineTreeRoot.action";
		//var req = {"treeType":treeType};
		location.href= "medicineTree_getMedicineTreeRoot.action?treeType="+treeType;
	//	$('#main',window.parent.document).attr("src","../../do/medicineTree_getMedicineTreeServiceChildren.action?nodeId="+nodeId+"&treeType="+treeType);
	});
	/*
	$("#contactTree").treeview( {
		animated : "medium",
		control : "#contactTreecontrol",
		persist : "location"
	});
	
*/

	//点击加减号
	$(".expandclose").toggle(
			function expand(){				
				$(this).parent().children("ul").show();
				
				$(this).html("<img src='/ag/zhh/images/minus.gif'></img>");
			},function close(){
			
				$(this).parent().children("ul").hide();
				$(this).html("<img src='/ag/zhh/images/plus.gif'></img>");
			});
	//点击连接
	$(".expandclose2").toggle(
			function expand(){				
				$(this).parent().children("ul").show();			
				$(this).prev().prev().html("<img src='/ag/zhh/images/minus.gif'></img>");
			},function close(){			
				$(this).parent().children("ul").hide();
				$(this).prev().prev().html("<img src='/ag/zhh/images/plus.gif'></img>");
			});
	$("input[name=udIfRadio]").click(function () {
		
		var deptType = $(this).attr("value");
		//alert(deptType);
		var treeType=$("#treeTypeSelect").attr("value");	
		
		if(treeType != "0001"){
			//alert("操作无效！");
			return;
		}
		location.href= "medicineTree_getMedicineTreeRoot.action?treeType="+treeType+"&deptType="+deptType;
	});
	
	//查询
	$("#find").click(function(){
		 var goal=document.getElementById("text").value; 
		 if(goal==null||goal=="") return;
		 $("a:contains('"+goal+"')").css("color","red").css("font-size","15px").parents().show();
		 var set=$("a:contains('"+goal+"')");		//获取第一个匹配的元素
		 var first = set.first();	
		 if(set.size() != 0)
		 {
		 var y=first[0].offsetTop;		//获取第一个元素的y坐标
		 document.body.scrollTop=y-200;		
		
		 }
		});
	//清除查询	
		$("#clear").click(function(){
			$("a").css("color","").css("font-size","");
		});
	
	//打开我的通信录	
	$("#myContactImg").click(function(){
		
		window.open("/ag/lwc/findAllContact_UserContactAction.action","newwindow",'height='+300+',width='+500+',top=50,left=50,toolbar=no,menubar=no,scrollbars=yes, resizable=yes,location=no, status=no')
		
		});
	//打开我的通信录	
	$(parent.window.frames['menuFrame'].document).find("#myContactLink").click(function(){

		//window.open("/ag/lwc/findAllContact_UserContactAction.action","newwindow",'height='+screen.height+',width='+screen.width+',top=10,left=0,toolbar=no,menubar=no,scrollbars=yes, resizable=yes,location=no, status=no')
		window.open("/ag/lwc/findAllContact_UserContactAction.action","newwindow",'height='+300+',width='+500+',top=300,left=400,toolbar=no,menubar=no,scrollbars=yes, resizable=yes,location=no, status=no')
		});

		
		


	
	//setTimeout(function(){$("#contree1").show();},5000);
	
	   var tips = $(".validateTips");
		
		//给出提示的函数
		function updateaddTips(t) {
			tips.text(t).addClass('ui-state-highlight');
			setTimeout(function() {
				tips.removeClass('ui-state-highlight',1000);
			}, 500);
		};	
		
/*
	$("input[type='checkbox']").click(function(){
		$(this).parents().attr("checked",$(this).attr("checked"));
		
		return true;
	});
	*/
	//信息提示框
	$("#msgdialog").dialog({
		autoOpen : false,
		/*height :300,*/
		width : '80%',
		resizable: true,
		modal : false,
		buttons : {
			'确定' : function()
			{
				$("#call li").remove();
			//	$.cookie("party",null ,options);
			
				$(this).dialog('close');
			},
			'取消':function(){
				$(this).dialog('close');
			}
		},
		close : function()
		{
			//不cookie删除
			  $(":checkbox").attr("checked",false);
	 	//	$.cookie("party","",{expires:-1});				
	 	//	$.cookie("messages","",{expires:-1});	
	 		$("#msgdialog").text("");
		}
	});
	//短信编辑的对话框
	 $("#smsdialog").dialog({
		autoOpen : false,
		/*height :300,*/
		width : '80%',
		resizable: true,
		modal : true,
		buttons : {
			'发送' : function()
			{		
		//获得短信发送号码和短信发送人之间的关联,存入cookie
			msg=$("#contend").text();
			
		 if(msg.length==0){updateaddTips("短信不能为空");return false;}
	     var cArr = msg.match(/[^x00-xff]/ig);
		 if((msg.length+(cArr == null ? 0:cArr.length))>200)
			{
				updateaddTips("不能超出100个汉字");return false;
			}
		    var addeddevs;			//手机号码字符串
		    
			    var temp = new Array();
			    var nameArray = new Array();			//人名的数组
			    var idArray = new Array();
			    var j=0;
			    $(":checkbox:checked").each(function(index)
					   {
						j=j+1;
						var contact = $(this).attr("name");
						var name = $(this).next("a").text();
						var contacts = contact.split(",");
							
								var CCellphone=contacts[1];
								if(CCellphone!=null)
								{
									temp[temp.length]=CCellphone;			//手机
								 $("<p id='"+CCellphone+"' name='"+name+"'/>").appendTo($("#msgdialog"));
								}
								nameArray[nameArray.length]=name;			//人名
								idArray[idArray.length]=  $(this).attr("value");
								
						});
			    if(j>0) 
			 addeddevs=temp.join(",");			//获取电话号码字符串
			 var ids = idArray.join(",");
			 var names = nameArray.join(",");
//			 alert("手机号码字符串："+addeddevs+"\n短信内容："+msg+" 人名字符串："+names+"  id字符串："+ids);
//			 	sendMessages(ids,names,addeddevs,msg);		//发送短信
			 	
			 /*
			  * 发送短信
			  */
				url_sendMessage = "/ag/dgm/sendMessage_messageSend.action";
				req_sendMessage = {
						'ids':ids,					//接收人的id集合。逗号形式
						'names':names,				//接收人的名字集合
						'callees':addeddevs,		//接收人的手机号码集合
						'msg':msg
				};
				$.post(url_sendMessage,req_sendMessage,function(data){
					alert(data.result);
				});
				$("#smsdialog").dialog('close');
			},
			'取消':function()
			{
				$(this).dialog('close');	
			}
		},
		close : function()
		{
			 $("#contend").text("");
			 tips.text("");
		}
	});

});


function msgdialog(text) {//信息提示框
	
	$("#msgdialog").html(" ");
	$("#msgdialog").html(text);
	$("#msgdialog").dialog('open');
}

$(this).scroll(function() {    // 页面发生scroll事件时触发   
            var bodyTop = 0;   
            if (typeof window.pageYOffset != 'undefined') {   
                bodyTop = window.pageYOffset;   
            }
             else if (typeof document.compatMode != 'undefined' && document.compatMode != 'BackCompat')
             {   
                bodyTop = document.documentElement.scrollTop;   
            }   
            else if (typeof document.body != 'undefined') {   
                bodyTop = document.body.scrollTop;   
            }   
  
            $("#contactmenu").css("top",bodyTop)   // 设置层的CSS样式中的top属性, 注意要是小写，要符合“标准” 
        }); 




